//
//  ScenesFoaRotator.cpp
//  ScenesPlayer
//
//  Created by Branch on 2017/5/2.
//  Copyright © 2017年 Scenes. All rights reserved.
//

#include "ScenesFoaRotator.h"

ScenesFoaRotator::ScenesFoaRotator(){

}

ScenesFoaRotator::~ScenesFoaRotator(){

}

void ScenesFoaRotator::rotator(float** src,float* matrix4,uint32_t nsamples){

    float* y = src[1];
    float* z = src[2];
    float* x = src[3];
    float Yr = 0;
    float Zr = 0;
    float Xr = 0;
    // Apply the rotation in the world space.
    
    // | m0  m4  m8 |   |Y|   | Y * m0 + Z * m4 + X * m8 |   | Yr |
    // | m1  m5  m9 | * |Z| = | Y * m1 + Z * m5 + X * m9 | = | Zr |
    // | m2  m6  m10|   |X|   | Y * m2 + Z * m6 + X * m10|   | Xr |

    for (uint32_t i = 0; i < nsamples; ++i) {
        Yr = *y * matrix4[0] + *z * matrix4[4] + *x * matrix4[8];
        Zr = *y * matrix4[1] + *z * matrix4[5] + *x * matrix4[9];
        Xr = *y * matrix4[2] + *z * matrix4[6] + *x * matrix4[10];
        *y++ = Yr;
        *z++ = Zr;
        *x++ = Xr;
    }
}
